<?php
declare(strict_types=1);

namespace App\Controller\Admin\V1\PointPosition;

use App\Controller\Admin\AdminController;
use App\Repositories\PointPositionCategoryRepository;
use App\Request\StorePointPositionCategoryRequest;

class CategoryController extends AdminController
{
    public function all()
    {
        $return= PointPositionCategoryRepository::getInstance()->all();
        return $this->response->success($return);
    }

    public function list(){
        $rows = $this->request->input('rows',10);
        $search=[];
        $orderBy= [
            [
                'field' => 'listorder',
                'sort' => 'desc'
            ],
            [
                'field' => 'id',
                'sort' => 'desc'
            ]
        ];
        $datas = PointPositionCategoryRepository::getInstance()->getList('*',$search,['limit'=>$rows],$orderBy);
        return $this->response->success($datas);
    }

    public function detail(){
        $id = $this->request->input('id');
        $question = PointPositionCategoryRepository::getInstance()->getById($id);
        return $this->response->success($question);
    }

    public function store(StorePointPositionCategoryRequest $request){
        $params = $request->all();
        $result = PointPositionCategoryRepository::getInstance()->store($params);
        if($result['success']){
            return $this->response->success([
                'id' => $result['data']->id
            ]);
        }
        return $this->response->error(10000,$result['msg']);
    }

    public function delete(){
        $id = $this->request->input('id');
        $result =PointPositionCategoryRepository::getInstance()->delete($id);
        if($result){
            return $this->response->success($result['data']);
        }
        return $this->response->error(10000,$result['msg']);
    }
}